var Amqp = require('../amqp').Amqp;
/**
 * Work with access tickets.
 *
 * The protocol control access to server resources using access tickets. A client must explicitly
 * request access tickets before doing work. An access ticket grants a client the right to use a
 * specific set of resources - called a "realm" - in specific ways.
 *
 * @exports Access as impl.Access
 * @class
 * @extends events.EventEmitter
 * @param handler
 */
function Access(/**handlers.Channel*/handler){
    var access = this;
    this.handler = handler;
    /**
     * Grant access to server resources.
     *
     * This method provides the client with an access ticket. The access ticket is valid within the
     * current channel and for the lifespan of the channel.
     *
     * @name Access#request
     * @event
     * @param {Object} args
     * @param {Number} args.ticket An access ticket granted by the server for a certain set of
     *      access rights within a specific realm. Access tickets are valid within the channel
     *      where they were created, and expire when the channel closes.
     */
    handler.addListener('Amqp.Access.RequestOk', function(frame){
        access.emit('request', frame.method.arguments);
    });
}
require('sys').inherits(Access, require('events').EventEmitter);
/**
 * Request an access ticket.
 *
 * This method requests an access ticket for an access realm. The server responds by granting the
 * access ticket. If the client does not have access rights to the requested realm this causes a
 * connection exception. Access tickets are a per-channel resource.
 *
 * @param {Object} args
 * @param {String} args.realm Must start with a slash "/" and continue with path names separated by
 *      slashes. A path name consists of any combination of at least one of [A-Za-z0-9] plus zero
 *      or more of [.-_+!=:].
 * @param {Boolean} args.exclusive Request exclusive access to the realm. If the server cannot
 *      grant this - because there are other active tickets for the realm - it raises a channel
 *      exception.
 * @param {Boolean} args.passive Request message passive access to the specified access realm.
 *      Passive access lets a client get information about resources in the realm but not to make
 *      any changes to them.
 * @param {Boolean} args.active Request message active access to the specified access realm.
 *      Acvtive access lets a client get create and delete resources in the realm.
 * @param {Boolean} args.write Request write access to the specified access realm. Write access
 *      lets a client publish messages to all exchanges in the realm.
 * @param {Boolean} args.read Request read access to the specified access realm. Read access lets a
 *      client consume messages from queues in the realm.
 */
Access.prototype.request = function(args){
    this.handler.call(Amqp.Class.Access, Amqp.Class.Access.Request, args);
};
exports.Access = Access;
